import { request } from '@/plugins/request';

// 获取公共文章列表
export const getArticles = params => {
  return request({
    method: 'GET',
    // 接口可在 github 上找到
    url: '/api/articles',
    params,
  });
};

// 获取公共文章列表
export const getYourFeedArticles = params => {
  return request({
    method: 'GET',
    // 接口可在 github 上找到
    url: '/api/articles/feed',
    params,
    // headers: {
    //   // 通过 vue tool 找到自己的 token
    //   Authorization: `Token eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MTEwOTY3LCJ1c2VybmFtZSI6IkFtY2VudCIsImV4cCI6MTYwMzQ1MDM4OX0.UXHLeAGf7_77dYdYG6DKKoYEO_aQAOki4fqYr4MJfVA`,
    // },
  });
};

// 添加点赞
export const addFavorite = slug => {
  return request({
    method: 'POST',
    // 接口可在 github 上找到
    url: `/api/articles/${slug}/favorite`,
  });
};

// 取消点赞
export const deleteFavorite = slug => {
  return request({
    method: 'DELETE',
    url: `/api/articles/${slug}/favorite`,
  });
};

// 获取文章详情
export const getArticle = slug => {
  return request({
    method: 'GET',
    url: `/api/articles/${slug}`,
  });
};

// 获取文章评论
export const getComments = slug => {
  return request({
    method: 'GET',
    url: `/api/articles/${slug}/comments`,
  });
};

// 新增文章
export const newArticle = data => {
  console.log('data', data);
  return request({
    method: 'POST',
    url: `/api/articles`,
    data,
  });
};
